package com.ejlchina.tool.util

import android.app.DownloadManager
import android.app.DownloadManager.Request.VISIBILITY_VISIBLE
import android.content.Context
import android.net.Uri
import android.os.Environment
import androidx.transition.Visibility
import com.ejlchina.tool.network.RemoteCtrlBoardVersion

class DownloadUtil(private val context: Context) {

    fun downloadFirmware(remoteCtrlBoardVersion: RemoteCtrlBoardVersion, downloadManager: DownloadManager): Long{
        val request = DownloadManager.Request(Uri.parse(remoteCtrlBoardVersion.url))
        request.setTitle("固件下载")
        request.setDescription("固件文件下载")
        request.setNotificationVisibility(VISIBILITY_VISIBLE)
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
        request.setDestinationInExternalFilesDir(context,Environment.DIRECTORY_DOWNLOADS,"${remoteCtrlBoardVersion.verNo}.bin")
        return downloadManager.enqueue(request)
    }
}